package com.twm.util;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.Charset;

/**
 * @ClassName EncryptionUtil
 * @Description TODO
 * @Author twm17
 * @Date 2020/11/14 10:42
 * @Version 1.0
 */
@Slf4j
public class EncryptionUtil {
    /**
     *密钥
     */
    private  final  static String SECRET_KEY = "twm";
    /**随机生成密钥*/
    private  final  static byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
    /** 构建*/
    private  final  static SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);

    /**
     *
     * @param value 加密算法
     * @return java.lang.String
     * @author twm
     * @date 2020/11/14
     */
    public static String encryption(byte[] value) {
        return aes.encryptHex(new String(value));
    }

    public static String decode(byte[] value) {
        byte[] decrypt = aes.decrypt(new String(value));
        return new String(decrypt);
    }
}
